import 'package:flutter/material.dart';

class UserPage extends StatefulWidget {
  @override
  _UserPage createState() => _UserPage();
}

class _UserPage extends State<UserPage> with AutomaticKeepAliveClientMixin {
  int count = 0;

  void add() {
    setState(() {
      count++;
    });
  }

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    print('UserPage initState');
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
        body: Center(
            child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
              Text('UserPage: $count', style: TextStyle(fontSize: 30)),
              RaisedButton(
                child: Text("退出回到登录"),
                onPressed: () {
                  Navigator.of(context).pushNamedAndRemoveUntil(
                      "/login", ModalRoute.withName("/login"));
                },
              ),
            ])),
        floatingActionButton: FloatingActionButton(
          heroTag: 'userFloatingActionButton',
          onPressed: add,
          child: Icon(Icons.add),
        ));
  }
}
